/// 打卡记录实体类
class CheckInRecord {
  final String date; // 日期，格式：yyyy-MM-dd
  final String imagePath; // 图片本地路径
  final String content; // 记录内容
  final DateTime createdAt; // 创建时间

  const CheckInRecord({
    required this.date,
    required this.imagePath,
    required this.content,
    required this.createdAt,
  });

  /// 从 JSON 创建对象
  factory CheckInRecord.fromJson(Map<String, dynamic> json) {
    return CheckInRecord(
      date: json['date'] as String,
      imagePath: json['imagePath'] as String,
      content: json['content'] as String,
      createdAt: DateTime.parse(json['createdAt'] as String),
    );
  }

  /// 转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'date': date,
      'imagePath': imagePath,
      'content': content,
      'createdAt': createdAt.toIso8601String(),
    };
  }

  /// 复制对象并修改部分属性
  CheckInRecord copyWith({
    String? date,
    String? imagePath,
    String? content,
    DateTime? createdAt,
  }) {
    return CheckInRecord(
      date: date ?? this.date,
      imagePath: imagePath ?? this.imagePath,
      content: content ?? this.content,
      createdAt: createdAt ?? this.createdAt,
    );
  }

  @override
  String toString() {
    return 'CheckInRecord(date: $date, imagePath: $imagePath, content: $content, createdAt: $createdAt)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is CheckInRecord &&
        other.date == date &&
        other.imagePath == imagePath &&
        other.content == content &&
        other.createdAt == createdAt;
  }

  @override
  int get hashCode {
    return date.hashCode ^
        imagePath.hashCode ^
        content.hashCode ^
        createdAt.hashCode;
  }
}
